home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 32.0 KB | 1,181 lines | [TEXT/MPS ] |
- // UCalc.h
- // Copyright © 1986-96 by Apple Computer, Inc. All rights reserved.
-
- // This MacApp sample implements a simple spreadsheet
- // This version, created Christmas Day 1989 by Larry Tesler, uses
- // classes TPrimaryScroller and TSecondaryScroller in USynchScroller
- // [instead of defining its own TCalcScroller and four AutoScroll methods]
- // to achieve synchronous scrolling [instead of near-synchronous scrolling]
- // and to enable auto-scrolling during column resizing.
-
- /*
- Change History:
- 03/29/96 srf GetPrintExtent/CalcViewPerPage returns a VRect
- 3/23/96 srf TCalcTypingCommand::DoMakeTypingCommand takes a CStr2 now.
- 3/23/96 srf TCalcTypingCommand::AddCharacter takes a CStr2 now.
- 3/18/96 srf Made better use of TView calls that return CRect/VPoint/VRect
- 3/4/96 srf Fix the alignment for structures written/read to disk to be
- compatible for both 68K and PPC versions.
- 1/4/96 TWB Get rid of TFileHandler.
- 12/21/95 TWB Remove SetupUndoMenu.
- ----- 3.3 -----
- ----- 3.3b1 -----
- 07/31/95 srf cPrintSelection is declared in MacApp now.
- 6/28/95 TWB Don't need to include ULoMem.
- 3/28/95 TWB Alphabetized the includes.
- 3/13/95 TWB Change Free methods to destructors.
- */
-
- #ifndef __UCALC__
- #define __UCALC__
-
- // Calc
-
- #ifndef __CALCUTILITIES__
- #include "CalcUtilities.h"
- #endif
-
- // MacApp
-
- #ifndef __MACAPPTYPES__
- #include "MacAppTypes.h"
- #endif
-
- #ifndef __UADORNERS__
- #include "UAdorners.h"
- #endif
-
- #ifndef __UAPPLEEVENTS__
- #include "UAppleEvents.h"
- #endif
-
- #ifndef __UAPPLICATION__
- #include "UApplication.h"
- #endif
-
- #ifndef __UASSOCIATION__
- #include "UAssociation.h"
- #endif
-
- #ifndef __UBEHAVIOR__
- #include "UBehavior.h"
- #endif
-
- #ifndef __UCLIPBOARDMGR__
- #include "UClipboardMgr.h"
- #endif
-
- #ifndef __UCOMMAND__
- #include "UCommand.h"
- #endif
-
- #ifndef __UCONTROL__
- #include "UControl.h"
- #endif
-
- #ifndef __UDEPENDENCIES__
- #include "UDependencies.h"
- #endif
-
- #ifndef __UDESIGNATOR__
- #include "UDesignator.h"
- #endif
-
- #ifndef __UDOCUMENT__
- #include "UDocument.h"
- #endif
-
- #ifndef __UEDITIONDOCUMENT__
- #include "UEditionDocument.h"
- #endif
-
- #ifndef __UEVENT__
- #include "UEvent.h"
- #endif
-
- #ifndef __UEVENTHANDLER__
- #include "UEventHandler.h"
- #endif
-
- #ifndef __UFAILURE__
- #include "UFailure.h"
- #endif
-
- #ifndef __UFILE__
- #include "UFile.h"
- #endif
-
- #ifndef __UFILEBASEDDOCUMENT__
- #include "UFileBasedDocument.h"
- #endif
-
- #ifndef __UGEOMETRY__
- #include "UGeometry.h"
- #endif
-
- #ifndef __UGRABBERTRACKER__
- #include "UGrabberTracker.h"
- #endif
-
- #ifndef __UGRIDVIEW__
- #include "UGridView.h"
- #endif
-
- #ifndef __ULIST__
- #include "UList.h"
- #endif
-
- #ifndef __UMACGLOBALS__
- #include "UMacAppGlobals.h"
- #endif
-
- #ifndef __UMACAPPUTILITIES__
- #include "UMacAppUtilities.h"
- #endif
-
- #ifndef __UMEMORY__
- #include "UMemory.h"
- #endif
-
- #ifndef __UMENUMGR__
- #include "UMenuMgr.h"
- #endif
-
- #ifndef __UOBJECT__
- #include "UObject.h"
- #endif
-
- #ifndef __UPATCH__
- #include "UPatch.h"
- #endif
-
- #ifndef __UPRINTHANDLER__
- #include "UPrintHandler.h"
- #endif
-
- #ifndef __UPRINTING__
- #include "UPrinting.h"
- #endif
-
- #ifndef __USCROLLER__
- #include "UScroller.h"
- #endif
-
- #ifndef __USECTION__
- #include "USection.h"
- #endif
-
- #ifndef __USTREAM__
- #include "UStream.h"
- #endif
-
- #ifndef __USYNCHSCROLLER__
- #include "USynchScroller.h"
- #endif
-
- #ifndef __UTECOMMANDS__
- #include "UTECommands.h"
- #endif
-
- #ifndef __UTEVIEW__
- #include "UTEView.h"
- #endif
-
- #ifndef __UVIEW__
- #include "UView.h"
- #endif
-
- #ifndef __UWINDOW__
- #include "UWindow.h"
- #endif
-
- // Toolbox
-
- #ifndef __ALIASES__
- #include <Aliases.h>
- #endif
-
- #ifndef __APPLEEVENTS__
- #include <AppleEvents.h>
- #endif
-
- #ifndef __BALLOONS__
- #include <Balloons.h>
- #endif
-
- #ifndef __CONTROLS__
- #include <Controls.h>
- #endif
-
- #ifndef __DEVICES__
- #include <Devices.h>
- #endif
-
- #ifndef __DIALOGS__
- #include <Dialogs.h>
- #endif
-
- #ifndef __EDITIONS__
- #include <Editions.h>
- #endif
-
- #ifndef __EVENTS__
- #include <Events.h>
- #endif
-
- #ifndef __FILES__
- #include <Files.h>
- #endif
-
- #ifndef __FONTS__
- #include <Fonts.h>
- #endif
-
- #ifndef __FP__
- #include <fp.h>
- #endif
-
- #ifndef __MEMORY__
- #include <Memory.h>
- #endif
-
- #ifndef __MENUS__
- #include <Menus.h>
- #endif
-
- #ifndef __OSUTILS__
- #include <OSUtils.h>
- #endif
-
- #ifndef __PACKAGES__
- #include <Packages.h>
- #endif
-
- #ifndef __QUICKDRAW__
- #include <Quickdraw.h>
- #endif
-
- #ifndef __SCRAP__
- #include <Scrap.h>
- #endif
-
- #ifndef __SEGLOAD__
- #include <SegLoad.h>
- #endif
-
- #ifndef __TEXTEDIT__
- #include <TextEdit.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #ifndef __TRAPS__
- #include <Traps.h>
- #endif
-
- #ifndef __WINDOWS__
- #include <Windows.h>
- #endif
-
-
- class TRow;
- class TRowsView;
- class TRowList;
- class CRowIterator;
- class TColumn;
- class TColumnsView;
- class TColumnList;
- class CColumnIterator;
- class TCell;
- class TCellList;
- class CCalcCellIterator;
- class CSelectedExistingCalcCellIterator;
-
-
- const short kMaxRows = 120; // Maximum row number (arbitrary)
-
- typedef short RowNumber; // RANGE = 0..kMaxRows; Zero indicates no row.
-
- const short kMaxColumns = 64; // Maximum column number (arbitrary)
-
- typedef short ColumnNumber; // RANGE = 0..kMaxColumns;
-
- const short kMaxValueLength = 24; // Max. length of a value as a CString
-
- const OSType kSignature = 'SS12'; // Application signature.
- const OSType kFileType = 'SF12'; // Data file type.
-
- const int kCalcWindowType = 1001; // Resource id of the spreadsheet window
-
- enum CalcMode
- {
- kManual, kAutomatic
- };
-
-
- typedef double ValueType;
- typedef double DiskValueType; // extendeds are for internal use only
- typedef CStr31 ValueString; // This isn't exactly what it used to be
- // Should be constrained by kMaxValueLength!!!!!
-
- typedef decform ValueFormat; // Have SANE display numeric values in decimal
-
- enum KindOfCell
- {
- kEmptyCell, kValueCell, kTextCell, kErrorCell
- };
-
-
- enum EvalResult
- {
- kNoError, kMissingRightParen, kSelfReference, kErrorCellReference, kBadNumber, kIllegalCharacter, kBadCellReference, kGarbageAtEnd
- };
-
-
- enum TypeOfSelection
- {
- kNoSelection, kCellSelection, kRowSelection, kColumnSelection, kAllSelection
- };
-
-
- enum TypeOfStyle
- {
- kNoStyle, kGeneral, kDecimalStyle, kNoDecimal, kScientific, kUnknownStyle
- };
-
-
- enum TypeOfLine
- {
- kNoLine, // for DrawLine routine
- kSolidLine, kBoldLine, kVDottedLine, kHDottedLine, kRowSeparator, kColumnSeparator
- };
-
-
- //============================================================================================
- // Data read from or written to disk files or exchanged via clip must be built to use the same
- // alignment. We choose to center on mac68K alignment. In your application you may choose any
- // data alignment that you wish, so long as both your PPC and 68K code agree on it.
- //============================================================================================
- #if PRAGMA_ALIGN_SUPPORTED
- #pragma options align=mac68k
- #endif
-
- struct FormatRecord
- {
- TypeOfStyle fStyle;
- SignedByte fJustification;
- char fDigits;
- char fFontNumber;
- char fFontSize;
- Style fFontStyle;
- };
- typedef FormatRecord * FormatPtr;
-
- struct CalcDocDiskInfo
- {
- CRect dimensions;
- short allocatedCells;
- short allocatedRows;
- short allocatedColumns;
- RowNumber editRow;
- ColumnNumber editColumn;
- CalcMode calcMode;
- TypeOfSelection selectionType;
- };
-
- // Info about the document's rows
- struct RowDiskInfo
- {
- short number;
- };
-
- // Info about the document's columns
- struct ColumnDiskInfo
- {
- FormatRecord format;
- short number;
- short width;
- };
-
- // The document's cells
- // row/column coordinate read/written separately
- struct CellDiskInfo
- {
- CStr255 formula;
- short noOfReferences;
- DiskValueType value;
- KindOfCell kind;
- EvalResult error;
- };
-
-
- struct ScrapInfoRecord
- {
- CRect selection;
- short noOfCells;
- };
-
- // row/column coordinate read/written separately
- // cell length read/written separately
- struct CellScrapInfo
- {
- CStr255 formula;
- FormatRecord format;
- };
-
- #if PRAGMA_ALIGN_SUPPORTED
- #pragma options align=reset
- #endif
- //============================================================================================
- //============================================================================================
-
-
- const OSType kTextScrapType = 'TEXT';
- const OSType kCalcScrapType = 'CALC';
-
- const short kCellWidth = 80; // default width of each cell
- const short kCellHeight = 17; // default height of each cell
- const short kCellHBorder = 2; // pixels separating cell contents from
- // left/right edge
-
- const short kCellFont = applFont;
- const short kCellFontSize = 10;
- const short kRowTitleWidth = 32; // width of row titles
- const short kColumnTitleHeight = 20; // height of column titles
- const short kTitlesFont = applFont; // font for column/row titles
- const short kTitlesFontSize = 10; // font size for column/row titles
-
- const short kEntryFont = applFont; // default font of cell contents
- const short kEntryFontSize = 10; // default font size of cell contents
- const short kEntryHeight = 20; // height of the cell entry view
-
- const CalcMode kCalcMode = kAutomatic; // default calculation mode
- const Boolean kForceAutomatic = TRUE; // force automatic calculation
- const Boolean kUpdateDependencies = TRUE; // set cell's dependents
-
- const short kDefaultJustification = teCenter; // default cell justification
- const short kNoJustification = 2; // constant representing no justification
-
- const short kValuePrecision = 18; // digits of precision in our values
- const short kTELength = (80 * 5); // number of characters in the text edit
- // field
-
- const short kCellsViewHelp = 128;
- const short kColsViewHelp = kCellsViewHelp;
- const short kRowsViewHelp = kCellsViewHelp;
-
- // Command Constants
-
- const short cRecalculate = 401;
- const short cAutoCalc = 403;
- const short cManualCalc = 404;
- const short cGeneral = 501;
- const short cNoDecimal = 503;
- const short cDecimal = 504;
- const short cScientific = 505;
- const short cSystemJustify = 506;
- const short cForceLeftJustify = 507;
- const short cRightJustify = 508;
- const short cCenter = 509;
- const short cSelecting = 1000;
- const short cSizeColumn = 1001;
- const short cCutText = 1103;
- const short cCopyText = 1104;
- const short cClearText = 1106;
- const short cCutCells = 1203;
- const short cCopyCells = 1204;
- const short cClearCells = 1206;
- const short cStandardCut = 1303;
- const short cStandardCopy = 1304;
- const short cStandardClear = 1306;
-
- const short mWidthChanged = 1002;
- const short mValueChanged = 1003;
-
- // Cursor Resource ID's
-
- const short kColumnSizingCursor = 256; // cursor for resizing a column
- const short kRowSizingCursor = 257; // cursor for resizing a row--UNUSED
-
-
- //--------------------------------------------------------------------------------------------------
- void ReadCellCoordinate(TFile* aFile,
- RowNumber& r,
- ColumnNumber& c);
-
-
- //--------------------------------------------------------------------------------------------------
- // TCalcApplication:
- //--------------------------------------------------------------------------------------------------
-
- class TCalcApplication : public TApplication
- {
- MA_DECLARE_CLASS;
-
- public:
- virtual~ TCalcApplication();
- // Destructor
-
- virtual void ICalcApplication();
- // Initializes the Application
-
- virtual void AboutToLoseControl(Boolean convertClipboard);// override
- // Override to reset Edit menu items for incoming DAs
-
- virtual TDocument* DoMakeDocument(CommandNumber itsCommandNumber,
- TFile* itsFile);// override
- // Launches a TCalcDocument
-
- virtual TView* MakeViewForAlienClipboard(); // override
- // Handle data that was left in the Clipboard by forces outside the application
-
- };
-
-
- //--------------------------------------------------------------------------------------------------
- // Forward class declaration.
- //--------------------------------------------------------------------------------------------------
-
- class TCellsView;
- class TEntryView;
- class TCoordView;
-
-
- //--------------------------------------------------------------------------------------------------
- // TCalcDocument:
- //--------------------------------------------------------------------------------------------------
-
- class TCalcDocument : public TEditionDocument
- {
- MA_DECLARE_CLASS;
-
- public:
- //------------------------------------------------------------------------------------
- // Initialization and termination
- //------------------------------------------------------------------------------------
-
- TCalcDocument();
- // Put the document in a safely free-able state
-
- virtual void ICalcDocument(TFile* itsFile,
- const CRect& dimensions);
- // Initialize the document
-
- virtual void DoInitialState(); // override
- // Initialize allocation counts
-
- virtual void DoMakeViews(Boolean forPrinting);// override
- // Launch the views which are seen in the document's window
-
- virtual~ TCalcDocument(); // override
- // Free the document
-
- virtual void DoToPublisher(TCell* theCell,
- TPublisher* aPublisher);
-
- virtual void FreeData(); // override
- // Delete the cells, rows, and columns
-
- //------------------------------------------------------------------------------------
- // Filing OVERRIDES
- //------------------------------------------------------------------------------------
-
- virtual void DoNeedDiskSpace(TFile* itsFile,
- long& dataForkBytes,
- long& rsrcForkBytes);// override
- // Tells how many bytes of disk space will be required to store the
- // data for the document in a file on disk
-
- virtual void DoRead(TFile* aFile,
- Boolean forPrinting); // override
- // Reads in the data from the disk, when a document is Opened or Reverted
-
- virtual void DoWrite(TFile* aFile,
- Boolean makingCopy); // override
- // Writes the data to the disk, when a document is Saved
-
- //------------------------------------------------------------------------------------
- // Menu handling
- //------------------------------------------------------------------------------------
-
- virtual void DoSetupMenus(); // override
- // Enable menu commands
-
- virtual void DoMenuCommand(CommandNumber aCommandNumber);// override
- // Handle menu commands
-
- //------------------------------------------------------------------------------------
- // Cell management
- //------------------------------------------------------------------------------------
-
- virtual void AddCell(TCell* theCell,
- RowNumber r,
- ColumnNumber c);
- // Add the cell to the document
-
- virtual Boolean CellExists(RowNumber r,
- ColumnNumber c);
- // Is there a cell object at these coordinates?
-
- virtual void DeleteCell(RowNumber r,
- ColumnNumber c);
- // Mark the cell at the given coordinates as deleted
-
- virtual Boolean IsExistingCell(TCell* aCell);
-
- virtual void EditCell();
- // Change the formula of the cell being edited to the CString in the entry view
-
- virtual void FreeCell(TCell* theCell);
- // Free the specified cell object
-
- virtual void FreeDeletedCells();
- // Free each cell object that is marked deleted
-
- virtual TCell* GetCell(RowNumber r,
- ColumnNumber c);
- // Return the cell object for the given coordinates.
-
- virtual TCell* GetExistingCell(RowNumber r,
- ColumnNumber c);
- // Return the cell object or NULL if no cell is allocated for the given coordinates.
-
- virtual Boolean IsAutoCalc();
- // Evaluates fCalcMode == kAutomatic
-
- virtual void SetEntry(RowNumber r,
- ColumnNumber c);
- // Set the text in the entry view to the formula in the cell at the given
- // coordinates
-
- virtual void UndeleteCell(RowNumber r,
- ColumnNumber c);
- // If there is a cell at the given coordinates, mark it undeleted
-
- //------------------------------------------------------------------------------------
- // Row management
- //------------------------------------------------------------------------------------
-
- virtual void AddRow(TRow* theRow);
- // Add the row to the document
-
- virtual TRow* GetRow(RowNumber r);
-
- virtual Boolean RowExists(RowNumber r);
-
- //------------------------------------------------------------------------------------
- // Column management
- //------------------------------------------------------------------------------------
-
- virtual void AddColumn(TColumn* theColumn);
- // Add the column to the document
-
- virtual Boolean ColumnExists(ColumnNumber c);
-
- virtual TColumn* GetColumn(ColumnNumber c);
-
- //------------------------------------------------------------------------------------
- // Ranges of cells
- //------------------------------------------------------------------------------------
-
- virtual Boolean CellInRange(short r,
- short c,
- CRect& range);
- // Do the given coordinates fall within the range?
-
- virtual void ConstrainToUsedCells(CRect& cellRange);
- // Shrink the range of cells to exclude unallocated cells, if possible
-
- virtual void DoRecalculate(Boolean forceAutomatic,
- Boolean setDependents);
- // Recalculate all cells if fCalcMode == kAutomatic, otherwise just selected cells
-
- //------------------------------------------------------------------------------------
- // Edition Manager Support
- //------------------------------------------------------------------------------------
-
- virtual void SetUserSelection(TDesignator* newSelection);
- // Sets the designator for the user selection (if any).
-
- virtual void UserSelectionChanged(TView* changedView);// override
-
- virtual void DoWriteData(const OSType aScrapType,
- TDesignator* aDesignator,
- TStream* aStream); // override
- // Given a designator and a stream, writes the designated data to the stream.
-
- virtual void DoWritePrivateTypes(TDesignator* aDesignator,
- TStream* aStream);
- // called by DoWriteData if aScrapType == kCalcScrapType
-
- virtual void DoReadData(const OSType aScrapType,
- TDesignator* aDesignator,
- TStream* aStream,
- long count); // override
- // Given a designator and a stream, read the designated data from the stream.
-
- virtual void DoReadPrivateTypes(TDesignator* aDesignator,
- TStream* aStream);
- // called by DoReadData if aScrapType == kCalcScrapType
-
- virtual void DoReadTEXT(TDesignator* aDesignator,
- TStream* aStream,
- long length);
- // called by DoReadData if aScrapType == 'TEXT'
-
- virtual void AddPublisherDependency(TSection* aSection);
- // Create a dependency between an publisher and its published cells.
-
- virtual void AddSectionAndBorder(TSection* aSection);
- // if the section is a publisher, create a dependency between it and all
- // published cells.
-
- virtual void DoPostMakeViews(Boolean forPrinting);
- // Iterate over the sections and create the dependencies between a publishers
- // and its published cells.
-
- virtual void DoAddBorder(TSection* aSection);
- // creates a border for the given section
-
- virtual void DoDeleteBorder(TSection* aSection);
- // deletes a border for the given section
-
- virtual void RevealSelection(TDesignator* aSelection);
-
- //------------------------------------------------------------------------------------
- // data members
- //------------------------------------------------------------------------------------
- public:
- CRect fDimensions; // the document's dimensions
-
- CRect fInUseBounds; // the area of the document that is in use
-
- TCellList* fCells;
-
- TStandardDependencySpace* fDependencies;
-
- TCell* fEditCell; // the cell being edited (the current selection)
-
- TRowList* fRows;
-
- TColumnList* fColumns;
-
- TCellsView* fCellsView; // the view of the cells themselves
-
- TRowsView* fRowsView; // the view of the row numbers
-
- TColumnsView* fColumnsView; // the view of the column letters
-
- TEntryView* fEntryView; // the view for entering/editing cell values
-
- TCoordView* fCoordView; // the view that shows the selected cell's coordinates
-
- short fRowOffset;
-
- short fColumnOffset;
-
- short fAllocatedCells; // the number of allocated cells
-
- short fAllocatedRows; // the number of allocated rows
-
- short fAllocatedColumns; // the number of allocated columns
-
- short fNoOfRows; // maximum number of rows
-
- short fNoOfColumns; // maximum number of columns
-
- RowNumber fEditRow; // the row of the cell being edited
-
- ColumnNumber fEditColumn; // the column of the cell being edited
-
- CalcMode fCalcMode; // Manual or Automatic recalculation
-
- TypeOfSelection fSelectionType;
-
- Boolean fColumnIsSelected; // a column has been selected
-
- };
-
-
- //--------------------------------------------------------------------------------------------------
- // TCalcWindow:
- //--------------------------------------------------------------------------------------------------
-
- class TCalcWindow : public TWindow
- {
- MA_DECLARE_CLASS;
-
- public:
- virtual~ TCalcWindow();
- // Destructor
-
- virtual void DoPostCreate(TDocument* itsDocument);
-
- virtual void Draw(const VRect& area); // override
-
- };
-
-
- //--------------------------------------------------------------------------------------------------
- // TCellsView is the view used to show the cell values.
- //--------------------------------------------------------------------------------------------------
-
- class TCellsView : public TTextGridView
- {
- MA_DECLARE_CLASS;
-
- public:
-
- virtual~ TCellsView();
- // Destructor
-
- virtual void CreatePublisherAdorner(TPublisher* aPublisher);
-
- virtual void CreateSubscriberAdorner(TSubscriber* aSubscriber);
-
- virtual void ComputeBorderRgn(RgnHandle itsBorderRegion,
- RgnHandle itsDesignation);
-
- //--------------------------------------------------------------------------------------------------
- // Initialization and termination
- //--------------------------------------------------------------------------------------------------
-
- virtual void ICellsView(TCalcDocument* itsDocument,
- Boolean forClipboard,
- TView* itsParent);
- // Initialize the view
-
- virtual void DoPostCreate(TDocument* itsDocument);
-
- //--------------------------------------------------------------------------------------------------
- // Commands and menus
- //--------------------------------------------------------------------------------------------------
-
- virtual void DoMouseCommand(VPoint& theMouse,
- TToolboxEvent* event,
- CPoint hysteresis);// override
-
- virtual void DoSetupMenus(); // override
-
- virtual void DoMenuCommand(CommandNumber aCommandNumber);// override
- // Handle menu commands
-
- virtual void DoKeyEvent(TToolboxEvent* event);// override
-
- //--------------------------------------------------------------------------------------------------
- // Display and Selection
- //--------------------------------------------------------------------------------------------------
-
- virtual void AdornCol(short aCol,
- const VRect& area); // override
- // Draw a column delimiter ("adornment") in the given area
-
- virtual void AdornRow(short aCol,
- const VRect& area); // override
- // Draw a row delimiter in the given area
-
- virtual Handle DesignatorAsTEXT(TDesignator* aDesignator);
-
- virtual Boolean DoIdle(IdlePhase phase); // override
- // Checks the state of the option key and decides whether to make the cursor
- // need to be reset. We used to use gAlwaysTrackCursor, but this is better.
-
- virtual void DoSetCursor(const VPoint& localPoint,
- RgnHandle cursorRegion);// override
-
- virtual void DrawCell(GridCell aCell,
- const VRect& aRect); // override
- // Draw the cell's value, using the proper justification
-
- virtual CRect GetVisibleCells();
- // Return a rectangle giving the cells that are visible
-
- virtual Boolean IsCellVisible(GridCell aCell);
- // Tell whether the specified cell is visible or not
-
- virtual void PositionAtCell(GridCell aCell);
- // Redraw the views so that aCell is at the top left corner of the grid
-
- virtual void ReSelect(RgnHandle cellRegion);
- // Set the current selection to the given cells
-
- virtual void ReSelectCell(GridCell aCell);
- // Set the current selection to the given cell
-
- virtual void ScrollSelectionIntoView(Boolean redraw);// override
- // Scroll so that at least the top left cell of the selection is visible
-
- virtual void SetCell(GridCell aCell);
-
- virtual void SetColWidth(short aCol,
- short numOfCols,
- short aWidth); // override
-
- virtual void SetSelection(RgnHandle cellsToSelect,
- Boolean extendSelection,
- Boolean highlight,
- Boolean select); // override
- // Set the current selections to the specified cells. Adjust the entry and
- // coordinate views accordingly.
-
- virtual void UserSelectionChanged(TView* changedView);
- // invalidate all publisher/subscriber adorners when the user selection changes
-
- //--------------------------------------------------------------------------------------------------
- // Printing OVERRIDES
- //--------------------------------------------------------------------------------------------------
-
- virtual VCoordinate DoBreakFollowing(VHSelect vhs,
- VCoordinate previousBreak,
- Boolean& Automatic);// override
-
- virtual VRect GetPrintExtent();// override
- // Return the area to print, depending on whether the command was Print Selection
- // or Print.
-
- //--------------------------------------------------------------------------------------------------
- // Clipboard handling
- //--------------------------------------------------------------------------------------------------
-
- virtual Boolean ContainsClipType(ResType aType);// override
-
- virtual void WriteCalcScrap(Handle calcScrap);
-
- virtual void WriteTextScrap(Handle textScrap);
-
- virtual void WriteToDeskScrap(); // override
-
- #if qDebug
- virtual void DoDrawPageBreak(VHSelect vhs,
- short whichBreak,
- VCoordinate loc,
- Boolean Automatic);// override
- // For debugging printing only, draw lines showing the page breaks.
- #endif
-
- //------------------------------------------------------------------------------------
- // data members
- //------------------------------------------------------------------------------------
- public:
- TCalcDocument* fCalcDocument;
-
- Boolean fLastOptionKey; // true if option key down at last idle.
- // helps in tracking modifier keys for views
- // that care.
-
- };
-
-
- //--------------------------------------------------------------------------------------------------
- // TCalcPrintHandler
- //--------------------------------------------------------------------------------------------------
-
- class TCalcPrintHandler : public TStdPrintHandler
- {
- MA_DECLARE_CLASS;
-
- public:
-
- virtual~ TCalcPrintHandler();
- // Destructor
-
- virtual VPoint CalcViewPerPage();// override
-
- virtual void DoMenuCommand(CommandNumber aCommandNumber);// override
- // Overridden to handle Print Selection.
-
- virtual void DoSetupMenus(); // override
- // Overridden to handle Print Selection.
-
- //------------------------------------------------------------------------------------
- // data members
- //------------------------------------------------------------------------------------
- public:
- CommandNumber fCmdNumber;
-
- };
-
-
- //--------------------------------------------------------------------------------------------------
- // TEntryView uses TextEdit to display and edit the selected cell's formula.
- //--------------------------------------------------------------------------------------------------
-
- class TEntryView : public TTEView
- {
- MA_DECLARE_CLASS;
-
- public:
-
- virtual~ TEntryView();
- // Destructor
-
- virtual void DoPostCreate(TDocument* itsDocument);
-
- virtual void DoKeyEvent(TToolboxEvent* event);// override
-
- virtual TTETypingCommand* DoMakeTypingCommand(const CStr2& ch);// override
- // Actually returns a TCalcTypingCommand
-
- virtual void DoMouseCommand(VPoint& theMouse,
- TToolboxEvent* event,
- CPoint hysteresis);// override
-
- virtual void DoMenuCommand(CommandNumber aCommandNumber);// override
-
- virtual void DoSetupMenus(); // override
-
- // virtual void SetupUndoMenu(); // override
-
- virtual void Draw(const VRect& area); // override
-
- virtual Boolean WantsToBeTarget(); // override
-
- virtual void EditMode(Boolean editing);
- // Enter or leave TextEdit mode. In TextEdit mode (fTEditing==true),
- // the Undo command causes an undo of the latest TextEdit action;
- // in non-TextEdit mode, Undo brings back the previous CString (fOldString)
-
- virtual void GetAsString(CStr255& theString);
- // Return the current text as a CString
-
- virtual void SetActive(Boolean state); // Override
-
- virtual void SetEditMode();
- // Enter TextEdit mode and clear the current text
-
- virtual void SetToString(const CStr255& theString);
- // Set the current text to theString
-
- virtual void SwapStrings();
- // Exchange the current text with that saved in fOldString
-
- //------------------------------------------------------------------------------------
- // data members
- //------------------------------------------------------------------------------------
- public:
- CStr255 fOldString; // previous CString, for undo/redo
-
- TCalcDocument* fCalcDocument;
-
- Boolean fTouched;
-
- Boolean fTEditing; // true: TextEdit mode
-
- Boolean fFirstEdit; // true: undo to previous CString
-
- };
-
-
- //--------------------------------------------------------------------------------------------------
- // TCoordView is the view used to display the coordinates of the cell which is currently selected.
- //--------------------------------------------------------------------------------------------------
-
- class TCoordView : public TView
- {
- MA_DECLARE_CLASS;
-
- public:
-
- virtual~ TCoordView();
- // Destructor
-
- virtual void DoPostCreate(TDocument* itsDocument);
-
- virtual void Draw(const VRect& area); // override
- // Draws the view seen in the window. Every nonblank view MUST override this method
-
- //------------------------------------------------------------------------------------
- // data members
- //------------------------------------------------------------------------------------
- public:
- TCalcDocument* fCalcDocument;
-
- };
-
-
- //--------------------------------------------------------------------------------------------------
- // TCalcSelectCommand is a command object created to handle mouse movement when you
- // click in a TCellsView.
- //--------------------------------------------------------------------------------------------------
-
- class TCalcSelectCommand : public TCellSelectCommand
- {
- MA_DECLARE_CLASS;
-
- public:
-
- virtual~ TCalcSelectCommand();
- // Destructor
-
- virtual void ICalcSelectCommand(TCalcDocument* itsDocument,
- TGridView* itsView,
- VPoint& theMouse,
- Boolean theShiftKey,
- Boolean theCommandKey);
-
- virtual void ComputeNewSelection(GridCell& clickedCell);// override
-
- //------------------------------------------------------------------------------------
- // data members
- //------------------------------------------------------------------------------------
- public:
- TCalcDocument* fCalcDocument;
-
- };
-
-
- //--------------------------------------------------------------------------------------------------
- // TCalcTypingCommand: We define our own typing command in order to remember which cell the
- // typing was performed in. Then if the user makes another selection we can undo/redo the
- // correct cell.
- //--------------------------------------------------------------------------------------------------
-
- class TCalcTypingCommand : public TTETypingCommand
- {
- MA_DECLARE_CLASS;
-
- public:
- virtual~ TCalcTypingCommand();
- // Destructor
-
- virtual void ICalcTypingCommand(TTEView* itsTEView,
- const CStr2& itsFirstChar);// override
- // Initialize the command object. Save the current cell selection for later Undo/Redo
-
- virtual void AddCharacter(const CStr2& ch); // override
- // Overridden to keep text visible when it overflows the entry view's box
-
- virtual void UndoIt(); // override
- // Undo the typing in the target cell
-
- virtual void RedoIt(); // override
- // Redo the typing in the target cell
-
- //------------------------------------------------------------------------------------
- // data members
- //------------------------------------------------------------------------------------
- public:
- TCellsView* fCellsView;
-
- GridCell fTargetCell; // cell selected when command was created
-
- };
-
- //----------------------------------------------------------------------------------------
- // Globals defined by this unit
- //----------------------------------------------------------------------------------------
-
- extern ValueFormat gGeneralFormat; // SANE conversion formats
- extern ValueFormat gDecimalFormat;
- extern ValueFormat gNoDecimalFormat;
- extern ValueFormat gScientificFormat;
- extern ValueFormat gNoFormat;
- extern FormatRecord gDefaultFormat; // default cell format
-
- extern Pattern gColumnSeparatorPattern; // patterns for separator lines
- extern Pattern gRowSeparatorPattern;
-
- #endif
-